#! /bin/bash

echo ""

echo "Running serializerNode (logs/serializerNode.log) with enchanced priority"
nice -19 rosrun roboard_drivers serializerNode > logs/serializerNode.log &

echo "Running adcNode (logs/serializerNode.log)"
rosrun roboard_drivers adcNode > logs/adcNode.log &

echo "Running listenIR (logs/listenIR.log)"
rosrun saint_nr_9 listenIR > logs/listenIR.log &

echo "Running MotorControl (logs/MotorControl.log)"
rosrun saint_nr_9 MotorControl > logs/MotorControl.log &

echo "Running imuNode (logs/imuNode.log)"
rosrun roboard_drivers imuNode > logs/imuNode.log &

echo ""
echo "Nodes have begun to start, wait a second to let them initialize."
echo ""
echo "Press ANY key to send quit signals.."
echo ""
read -n 1 -s

kill -2 `pidof MotorControl` 2> /dev/null
if [ ! $? -eq 0 ]; then echo "Failed to quit MotorControl"; fi

kill -2 `pidof listenIR` 2> /dev/null
if [ ! $? -eq 0 ]; then echo "Failed to quit listenIR"; fi

kill -2 `pidof adcNode` 2> /dev/null
if [ ! $? -eq 0 ]; then echo "Failed to quit adcNode"; fi

kill -2 `pidof serializerNode` 2> /dev/null
if [ ! $? -eq 0 ]; then echo "Failed to quit serializerNode"; fi

kill -2 `pidof imuNode` 2> /dev/null
if [ ! $? -eq 0 ]; then echo "Failed to quit serializerNode"; fi

echo ""
echo "Done, there might still be running processes if they didn't respond to the quit signal."
echo ""

